package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;

/**
 * 工单/任务的来源类型
 */
public enum MaintenanceOrderSourceType implements BaseCodeEnum {

    CUSTOMER("customer", "客户"),
    ELECTRICIAN("electrician", "电工"),
    ADMIN("admin", "管理员"),
    INSPECTION("inspection", "自动巡查");

    @EnumValue
    private final String code;
    private final String displayName;

    MaintenanceOrderSourceType(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static MaintenanceOrderSourceType of(String code) {
        if (code == null) return null;
        for (MaintenanceOrderSourceType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
